GATE Exam  >  GATE Questions  >  Find the output#include <iostream>#defi... Start Learning for Free
Find the output
#include <iostream>
#define cnct(x,y) x##y
using namespace std;
class {
public:
int p,q,pq;
int f1()
{
cout<<p+q+pq+cnct(p,q)<<endl;
return (p+++q);
}
}c;
int main(){
c.p=5,c.q=6,c.pq=15;
cout<<c.f1();
return 0;
}
  • a)
    Error occurs due to absence of class name
  • b)
    41,11
  • c)
    80,11
  • d)
    80,12
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Find the output#include <iostream>#define cnct(x,y) x##yusing na...
41, 11
Class without name is allowed. In this case object of class is created along with definition.
cnct(x,y) x##y ,## is a preprocessor macro used for concatenation.
x##y= xy
Call this creates a single terms named xy,here in main pq; cnct(p,q) places value of pq in its position that is 15.
cout<<p+q+pq+cnct(p,q)
5+6+15+15=41
P+++q is interpreted here as p++ + q(1st two for post increment operator,3rd one operator for adding )
Plus operator(+) has higher precedence than post increment operator. So, Value of p & q (5 & 6) get added before p increments. So, p+++q->11
View all questions of this test
Most Upvoted Answer
Find the output#include <iostream>#define cnct(x,y) x##yusing na...
41, 11
Class without name is allowed. In this case object of class is created along with definition.
cnct(x,y) x##y ,## is a preprocessor macro used for concatenation.
x##y= xy
Call this creates a single terms named xy,here in main pq; cnct(p,q) places value of pq in its position that is 15.
cout<<p+q+pq+cnct(p,q)
5+6+15+15=41
P+++q is interpreted here as p++ + q(1st two for post increment operator,3rd one operator for adding )
Plus operator(+) has higher precedence than post increment operator. So, Value of p & q (5 & 6) get added before p increments. So, p+++q->11
Free Test
Community Answer
Find the output#include <iostream>#define cnct(x,y) x##yusing na...
B
Explore Courses for GATE exam

Similar GATE Doubts

Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer?
Question Description
Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer?.
Solutions for Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Find the output#include <iostream>#define cnct(x,y) x##yusing namespace std;class {public:int p,q,pq;int f1(){cout<<p+q+pq+cnct(p,q)<<endl;return (p+++q);}}c;int main(){c.p=5,c.q=6,c.pq=15;cout<<c.f1();return 0;}a)Error occurs due to absence of class nameb)41,11c)80,11d)80,12Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev